﻿using BsForApi;
using BsForApi.Model;
using BsForApi.Model.Account;
using BsForApi.Model.JDOout;
using HCDV;
using HCDV.HCSP;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Services;

namespace WebService1
{
    public static class info
    {
        static info()
        {
            BaseConfig.Dbtype = ConfigurationSettings.AppSettings["dbtypehc"];
            if (BaseConfig.Dbtype == "mysql")
            {

                BaseConfig.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString2"];
            }
            else
            { BaseConfig.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"]; }
        }
    }
    /// <summary>
    /// Service1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {
        static Service1()
        {
            BaseConfig.Dbtype = ConfigurationSettings.AppSettings["dbtypehc"];
            if (BaseConfig.Dbtype == "mysql")
            {

                BaseConfig.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString2"];
            }
            else
            { BaseConfig.ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"]; }
        }

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }


        [WebMethod]
        public DataTable getInfo(string id, string key, string infos)
        {
            if (key != "ccbhc") return null;
            try
            {
                using (dbsimple db = new dbsimple())
                { return db.Query(infos); }
            }
            catch (Exception e)
            { return null; }
        }
        [WebMethod]
        public bool spsql(string id, string key, string infos)
        {
            if (key != "ccbhc") return false;
            try
            {
                using (dbsimple db = new dbsimple())
                { return db.SpExe(infos); }
            }
            catch (Exception e)
            { return false; }
        }


        /// <summary>
        /// 登录操作
        /// </summary>
        /// <param name="userinfo">登录要素</param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<LoginOut> Login(Loginin userinfo)
        {
            return BsForApi.Account.Login(userinfo);
        }


        //        采收信息加载接口，接口编号api_getpick
        //入参：不能为空
        //入参：机构ID（登录接口返回），采收日期（yyyy-MM-dd）
        //返回要素<list>：采收批次号，地块名称，品种名称
        //采收批次说明：基地＋地块＋品种＋采收日期 作为一个采收批次标识。
        //格式为：1_01_01_2018-10-10(基地ID＋地块ID＋品种ID＋采收日期)
        /// <summary>
        ///  采收信息加载接口，接口编号api_getpick
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<List<PickListOut>> GetPickList(ApiIn<PickListInput> input)
        {
            return BsForApi.JDBs.GetPickList(input);
        }


        /// <summary>
        /// 发货目标信息加载
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<List<OrgInfoOutpunt>> GetCenterOrgList(ApiIn<string> input)
        {
            return BsForApi.JDBs.GetCenterOrgList(input);
        }


        /// <summary>
        /// 提交发货汇总信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
       [WebMethod]
        public ApiOut<string> PostPickSend(ApiIn<PickSendInput> input)
        {
            return BsForApi.JDBs.PostPickSend(input);
        }

        /// <summary>
        /// 发货汇总信息加载接口，接口编号api_getpicksend
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
       [WebMethod]
        public ApiOut<List<GetPickSendOut>> GetPickSend(ApiIn<GetPickSendInput> input)
        { return BsForApi.JDBs.GetPickSend(input); }

        /// <summary>
        /// 提交发货码信息接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<string> PostPickSendCode(ApiIn<PickSendCodeInput> input)
        { return BsForApi.JDBs.PostPickSendCode(input); }

        /// <summary>
        /// 加载发货码明细，接口编号api_getpicksendcode
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<List<PickSendCodeOutput>> GetPickSendCode(ApiIn<PickSendCodeInput> input)
        { return BsForApi.JDBs.GetPickSendCode(input); }

        /// <summary>
        /// 删除发货码
        /// </summary>
        /// <param name="input">Info：对应为发货码</param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<string> DelPickSendCode(ApiIn<string> input)
        {
            return BsForApi.JDBs.DelPickSendCode(input);
        }

        /// <summary>
        /// 根据发货码 获取待入库信息
        /// </summary>
        /// <param name="input">Info为发货码</param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<List<CenterAwaitInStoreInfo>> GetSendInfoByCode(ApiIn<string> input)
        { return BsForApi.JDBs.GetSendInfoByCode(input); }

        /// <summary>
        /// 根据发货码 提交库信息
        /// </summary>
        /// <param name="input">Info为发货码</param>
        /// <returns></returns>
        [WebMethod]
        public ApiOut<string> CenterInStoreByCodeInfo(ApiIn<CenterInStoreInfo> input)
        { return BsForApi.JDBs.CenterInStoreByCodeInfo(input); }

        [WebMethod(Description = "更新文件")]
        public string[] GetUrls()
        {
            string info = "http://jsapi.hcrain.cn/";
            var url = ConfigurationSettings.AppSettings["downfile"];
            string[] urls = url.Split(';');
            for(int i=0;i<urls.Length;i++)
            {
                urls[i] = info + urls[i];
            }
            return urls;
            
        }




    }
}